#include<stdio.h>
struct stick
{
	int length,diameter,code;
};
int main()
{
	int N,m;
	scanf("%d",&N);
	while(N--)
	{
		scanf("%d",&m);
		int i,j;
		struct stick st[m];
		for(i=0;i<m;i++)
		{
			scanf("%d %d %d",&st[i].length,&st[i].diameter,&st[i].code);
			
		}
		struct stick max={0,0,0};
		for (int i = 0; i < m; i++) 
		{
            if (st[i].length > max.length||(st[i].length == max.length && st[i].diameter< max.diameter )
                ||(st[i].length == max.length && st[i].diameter == max.diameter && st[i].code>max.code)) 
				{
                max = st[i];
                }
        	}
        printf("%09d\n",max.code);
    }
	return 0;
}
